local skel = fk.CreateSkill{
  name = "sj_dianjuren__zhimingruiqi",
}

Fk:loadTranslationTable{
  ["sj_dianjuren__zhimingruiqi"] = "致命锐器",
  [":sj_dianjuren__zhimingruiqi"] = "以下阶段开始时，你可以：<br>"..
    "摸牌阶段：令摸牌数改为1，然后令一名角色本回合的装备牌失效；<br>"..
    "出牌阶段：令使用牌数改为1，然后本回合你下次造成伤害时摸两张牌；<br>"..
    "弃牌阶段：令所须弃牌数改为1，然后你可以将一张牌当【出其不意】使用。",
  ["#sj_dianjuren__zhimingruiqi_draw"] = "致命锐器：你可以令摸牌数改为1，令一名角色本回合的装备牌失效",
  ["#sj_dianjuren__zhimingruiqi_play"] = "致命锐器：你可以令使用牌数改为1，本回合你下次造成伤害时摸两张牌",
  ["#sj_dianjuren__zhimingruiqi_dis"] = "致命锐器：你可以令所须弃牌数改为1，然后你可以将一张牌当【出其不意】使用",
  ["#sj_dianjuren__zhimingruiqi_use"] = "致命锐器：你可以将一张牌当【出其不意】使用",
  ["@@sj_dianjuren__zhimingruiqi_draw-turn"] = "装备失效",
  ["@@sj_dianjuren__zhimingruiqi_play-turn"] = "致命锐器",
}


skel:addEffect(fk.DrawNCards, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askToChoosePlayers(player,{
      targets = player.room:getAlivePlayers(),
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      cancelable = true,
      prompt = "#sj_dianjuren__zhimingruiqi_draw",
    })
    if #tos > 0 then
      event:setCostData(self,{tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    data.n = 1
    local to = event:getCostData(self).tos[1]
    player.room:setPlayerMark(to,"@@sj_dianjuren__zhimingruiqi_draw-turn",1)
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{
      skill_name = skel.name,
      prompt = "#sj_dianjuren__zhimingruiqi_play",
    })
  end,
  on_use = function (self, event, target, player, data)
    local list = {
      "@@sj_dianjuren__zhimingruiqi_play-turn",
      "sj_dianjuren__zhimingruiqi_damage-turn",
      "sj_dianjuren__zhimingruiqi_use-phase"
    }
    for _, name in ipairs(list) do
      player.room:setPlayerMark(player,name,1)
    end
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Discard
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{
      skill_name = skel.name,
      prompt = "#sj_dianjuren__zhimingruiqi_dis",
    })
  end,
  on_use = function (self, event, target, player, data)
    data.phase_end = true
    local room = player.room
    if not player:isNude() then
      room:askToUseVirtualCard(player,{
        name = "unexpectation",
        skill_name = skel.name,
        prompt = "#sj_dianjuren__zhimingruiqi_use",
        cancelable = true,
        card_filter = {
          n = 1,
        },
      })
    end
    if #table.filter(player:getCardIds("h"),function (id)
      return not player:prohibitDiscard(id)
    end) > 0 then --暂时这样耦吧
      room:askToDiscard(player, {min_num = 1, max_num = 1, include_equip = false, skill_name = "phase_discard", cancelable = false})
    end
  end,
})

skel:addEffect("invalidity", {
  invalidity_func = function (self, player, skill)
    return player:getMark("@@sj_dianjuren__zhimingruiqi_draw-turn") > 0 and skill:getSkeleton().attached_equip
  end,
})

skel:addEffect(fk.DamageCaused, {
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player:getMark("sj_dianjuren__zhimingruiqi_damage-turn") > 0
  end,
  on_use = function (self, event, target, player, data)
    player.room:setPlayerMark(player,"sj_dianjuren__zhimingruiqi_damage-turn",0)
    player:drawCards(2,skel.name)
  end,
})

skel:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player:getMark("sj_dianjuren__zhimingruiqi_use-phase") > 0
  end,
  on_use = function (self, event, target, player, data)
    player.room:addPlayerMark(player,"sj_dianjuren__zhimingruiqi_use-phase")
    player:endPlayPhase()
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function (self, player, card)
    return player:hasSkill(skel.name) and player:getMark("sj_dianjuren__zhimingruiqi_use-phase") > 1 and player.phase == Player.Play
  end,
})

return skel